package ua.kiev.tosik.price.database.factory;

import ua.kiev.tosik.price.database.dao.IClientsDao;
import ua.kiev.tosik.price.database.dao.IPricesDao;
import ua.kiev.tosik.price.database.dao.IPricesFilesDao;

abstract public class AbstractDbFactory {

	public static AbstractDbFactory getInstance(String dbType) throws Exception {
		if ( "Derby".equalsIgnoreCase(dbType) ) {
			return new DbFactoryDerby();
		} else if ( "Postgres".equalsIgnoreCase(dbType) ) {
			return new DbFactoryPgsql();
		} else {
			throw new IllegalDbType("Database " + dbType + " is not supported!");
		}
	}

	public abstract IClientsDao createClientsDao();
	public abstract IPricesFilesDao createPricesFilesDao();
	public abstract IPricesDao createPricesDao();

	private static class IllegalDbType extends Exception {

		private String message;

		public IllegalDbType(String msg) {
			super(msg);
			message = msg;
		}

		public String getMessage() {
			return message;
		}

		public String getLocalizedMessage() {
			return getMessage();
		}
	}
}
